A text editor using a Tree to hold
it's text and CodeMirror to display it.
In some ways this editor tries to wrap the underlying CodeMirror instance. When there's similar functionality, such as get selection, I would encourage you to use this editor's methods. With that said, CodeMirror is considered a public part of this Editor's API. Use it as needed, especially if you are trying to reuse some existing CodeMirror code.
Methods
Options
Text Content
- textContent() → String
- setTextContent(textContent)
- replaceTextInRange(range, insertedText)
Selection
- hasSelection() → Boolean
- selectedText() → String
- selectedRange() → Range
- selectedRanges() → Array.<Range>
- replaceSelection(text, select)
- setSelectedRange(range)
- setSelectedRanges(ranges)
Focus
- focus()
Commands
- commands() → Array.<Command>
- performCommand(commandName, options)
Geometry
- charCoords(lineCh) → Rect
- cursorCoords(lineCh) → Rect
- targetsAt(x, y) → TargetResult
Scrolling
- scrollRangeToVisible(range)
- scrollRectToVisible(rect)
- scrollTo(x, y)
- scrollToLine(line, offset)
Viewport
- viewportRange() → Range
Keymaps
- addKeyMap(map, bottom)
- removeKeyMap(map)
Util
Current
- currentWordRange() → Range
- currentSentenceRange() → Range
Folding
- isExpanded(node) → Boolean
- isCollapsed(node) → Boolean
- collapseNode(node)
- hideNodes(nodes)
- expandNode(node)
- expandToRevealNode(node)
Node Path
- nodePath() → Object
- setNodePath(nodePath)
Method Details
-
cm() → {CodeMirror}
-
Return the CodeMirror instance associated with this editor.
Returns:
- Type
- CodeMirror
-
tree() → {module:ft/core/tree.Tree}
-
Return the Tree that holds this editor's text content.
Returns:
-
openLink(link)
-
Open the given link. When running natively this method will try to use native methods to open the line.
Parameters:
Name Type Description linkString URL text.
-
option(name) → {Object}
-
Return the value of the given option.
Parameters:
Name Type Description nameString Returns:
- Type
- Object
-
setOption(name, value)
-
Set a new value for the given option.
Parameters:
Name Type Description nameString valueObject -
textContent() → {String}
-
Return the text content of this editor.
Returns:
- Type
- String
-
setTextContent(textContent)
-
Replace the text content of this editor with new text.
Parameters:
Name Type Description textContentString -
replaceTextInRange(range, insertedText)
-
Replace this editor's text in the specified range with new text.
Parameters:
Name Type Description rangemodule:ft/core/range.Range insertedTextString -
hasSelection() → {Boolean}
-
Return true if there is any selected text.
Returns:
- Type
- Boolean
-
selectedText() → {String}
-
Return all text selected.
Returns:
- Type
- String
-
selectedRange() → {module:ft/core/range.Range}
-
Return the primary selected range.
Returns:
-
selectedRanges() → {Array.<module:ft/core/range.Range>}
-
Return all selected ranges in this editor.
Returns:
- Type
- Array.<module:ft/core/range.Range>
-
replaceSelection(text, select)
-
Replace the selection(s) with the given string. By default, the new selection ends up after the inserted text. The optional select argument can be used to change this — passing "around" will cause the new text to be selected, passing "start" will collapse the selection to the start of the inserted text.
Parameters:
Name Type Argument Default Description textString Replacement text.
selectString <optional>
"end" start|around|end
-
setSelectedRange(range)
-
Set selected range of text.
Parameters:
Name Type Description rangemodule:ft/core/range.Range -
setSelectedRanges(ranges)
-
Set multiple selected ranges of text.
Parameters:
Name Type Description rangesArray.<module:ft/core/range.Range> -
focus()
-
Give the editor keyboard focus.
-
commands() → {Array.<Command>}
-
Returns all commands installed in this editor.
Returns:
- Type
- Array.<Command>
-
performCommand(commandName, options)
-
Perform the given command.
Parameters:
Name Type Argument Description commandNameString Command's name.
optionsObject <optional>
Command options.
-
charCoords(lineCh) → {Rect}
-
Return character coordinates for the given LineChar.
Parameters:
Name Type Description lineChLineChar Returns:
- Type
- Rect
-
cursorCoords(lineCh) → {Rect}
-
Return cursor coordinates for the given LineChar.
Parameters:
Name Type Description lineChLineChar Returns:
- Type
- Rect
-
targetsAt(x, y) → {TargetResult}
-
Return the node, text position, and text attributes at the given x,y position.
Parameters:
Name Type Description xNumber yNumber Returns:
- Type
- TargetResult
-
scrollRangeToVisible(range)
-
Scroll the given range to visible in the editor's viewport.
Parameters:
Name Type Description rangemodule:ft/core/range.Range -
scrollRectToVisible(rect)
-
Scroll the given rect to visible in the editor's viewport.
Parameters:
Name Type Description rectRect -
scrollTo(x, y)
-
Scroll the editor to a given (pixel) position.
Parameters:
Name Type Description xNumber yNumber -
scrollToLine(line, offset)
-
Scroll the editor to a given line and optional pixel offset.
Parameters:
Name Type Description lineNumber offsetNumber -
viewportRange() → {module:ft/core/range.Range}
-
Return range covering visible editor viewport.
Returns:
-
addKeyMap(map, bottom)
-
Attach a CodeMirror style key map to the editor.
Parameters:
Name Type Argument Default Description mapKeyMap KeyMap to add.
bottomObject <optional>
false If true map will be added to bottom of the list of keymaps and be procesed last.
-
removeKeyMap(map)
-
Remove a keymap added with
addKeyMap. Either pass in the key map object itself, or a string, which will be compared against the name property of the active key maps.Parameters:
Name Type Description mapKeyMap KeyMap to remove.
-
removeAndCleanupForCollection()
-
Used when writing specs. Removes scheduled timers and things like that.
-
currentWordRange() → {Range}
-
Returns:
- Type
- Range
-
currentSentenceRange() → {Range}
-
Returns:
- Type
- Range
-
isExpanded(node) → {Boolean}
-
Return true if the node doesn't have a fold at the end of it's line.
Parameters:
Name Type Description nodemodule:ft/core/node.Node Returns:
- Type
- Boolean
-
isCollapsed(node) → {Boolean}
-
Return true if the node is "collapsed". A node is consided collapsed if there is a fold at the end of it's line.
Parameters:
Name Type Description nodemodule:ft/core/node.Node Returns:
- Type
- Boolean
-
collapseNode(node)
-
Collapse the node by adding a fold to hide all of it's descendant nodes. Nothing will happen
Parameters:
Name Type Description nodemodule:ft/core/node.Node -
hideNodes(nodes)
-
Unlike
collapseNodewhich hides the descendants of the provided node, this function hides the nodes in the passed in array in folds. This method doesn't care about the node tree structure... it will just hide the individual nodes passed in. So for instance you could hide one sibling node and leave other siblings still visible.Parameters:
Name Type Description nodesArray.<module:ft/core/node.Node> -
expandNode(node)
-
Expand the node by removing the fold at the end of it's line.
Parameters:
Name Type Description nodemodule:ft/core/node.Node -
expandToRevealNode(node)
-
Remove all folds neccessary to reveal the given node in the editor.
Parameters:
Name Type Description nodemodule:ft/core/node.Node -
nodePath() → {Object}
-
The object returned by this method is private and undocumented for the time begin, except you can call
toString()on it to get the node path as a string.Returns:
nodePath
- Type
- Object
-
setNodePath(nodePath)
-
Parameters:
Name Type Description nodePathString Node path string